﻿using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Common
{
    public class Constant
    {
        public string GetValueByKey(string key)
        {
            const string val = "";
            FieldInfo[] p = GetType().GetFields(BindingFlags.Public | BindingFlags.Static);
            foreach (FieldInfo f in p)
            {
                var t = (ConstantKeyValue)f.GetValue(null);
                if (t != null && t.Key == key)
                    return t.Value;
            }
            return val;
        }

        public List<ConstantKeyValue> GetAll()
        {
            FieldInfo[] p = GetType().GetFields(BindingFlags.Public | BindingFlags.Static);
            return p.Select(f => (ConstantKeyValue) f.GetValue(null)).Where(t => t != null).ToList();
        }

        public List<ConstantKeyValue> GetAllByKey(params string[] keys)
        {
            FieldInfo[] p = GetType().GetFields(BindingFlags.Public | BindingFlags.Static);
            return p.Select(f => (ConstantKeyValue) f.GetValue(null)).Where(t => t != null && keys.Contains(t.Key)).ToList();
        }
    }
}
